﻿
@{
    ViewBag.Title = "Employee";
    Layout = "~/Views/Shared/Index.cshtml";
}
@model  List<YaYun.Models.Employee>
@{

}

<style>
  

    
    .wi {
        background-color: azure;
    }

    .re {
        background-color: pink;
    }

    .el-textarea__inner {
        resize: vertical;
        padding: 5px 15px;
        line-height: 1.5;
        box-sizing: border-box;
        width: 10%;
        font-size: inherit;
        color: #606266;
        background-color: #fff;
        background-image: none;
        border: 1px solid #dcdfe6;
        border-radius: 4px;
        transition: border-color .2s cubic-bezier(.645,.045,.355,1);
    }

    .el-button--primary {
        color: #fff;
        background-color: #409eff;
        border-color: #409eff;
    }

    .el-button {
        display: inline-block;
        line-height: 1;
        white-space: nowrap;
        cursor: pointer;
        background-color: #409eff;
        border: 1px solid #dcdfe6;
        color: #606266;
        -webkit-appearance: none;
        text-align: center;
        box-sizing: border-box;
        outline: none;
        margin: 0;
        transition: .1s;
        color: #fff;
        font-weight: 500;
        -moz-user-select: none;
        -webkit-user-select: none;
        -ms-user-select: none;
        padding: 12px 20px;
        font-size: 14px;
        border-radius: 4px;
    }

    .el-buttona {
        display: inline-block;
        line-height: 1;
        white-space: nowrap;
        cursor: pointer;
        background: #fff;
        border: 1px solid #dcdfe6;
        color: #606266;
        -webkit-appearance: none;
        text-align: center;
        box-sizing: border-box;
        outline: none;
        margin: 0;
        transition: .1s;
        font-weight: 500;
        -moz-user-select: none;
        -webkit-user-select: none;
        -ms-user-select: none;
        padding: 12px 20px;
        font-size: 14px;
        border-radius: 4px
    }

    #employeeForm {
        float: right;
        width: 80%;
    }
</style>

<div>
    <div style="">
        <h3>员工离职表</h3>
        

        <div class="add_emp" style="display:none">

            <h2>入职信息登记</h2>
            @using (Html.BeginForm())
            {
                <svg width="27" height="27" onclick="qiandao_close()" class="qiandao_close" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <path d="M8 8L40 40" stroke="#FF0000" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" />
                    <path d="M8 40L40 8" stroke="#FF0000" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" />
                </svg>
                <span>电话号码：</span> <input type="text" maxlength="11" name="phone" value="" /> <br /><br />
                <span>电子邮箱：</span> <input class="input-group" type="text" name="email" value="" /> <br /><br />
                <span>员工姓名：</span> <input type="text" name="EmployeeName" value="" /> <br /><br />
                <span>性别：</span> <input type="text" name="gender" value="" /> <br /><br />
                <span>部门：</span> <input type="text" name="department_id" value="" /><br /><br />
                <span>职务：</span> <input type="text" name="position_id" value="" /> <br /><br />
                <span>入职时间：</span> <input type="date" name="enter_date" value="" /> <br /><br />
                <input type="submit" value="提交" />
            }

        </div>
    </div>
    <table class="layui-table layui-form">
        <tr>
            <th class="emp_id_td">员工编号</th>
            <th class="emp_tr_t">员工姓名</th>
            <th class="emp_tr_t">手机号</th>
            <th class="emp_tr_t">邮箱</th>
            <th class="emp_tr_t">性别</th>
         
            <th class="emp_tr_t">职务</th>
            <th class="emp_tr_t">入职时间</th>
            <th class="emp_tr_t">状态</th>
            <th class="emp_tr_t">复职</th>

        </tr>
        @{
            int numid = 1;
        }
        @foreach (var item in Model)
        {
            <tr class="tr_hover">
                <td class="emp_id_td">@item.id</td>
                <td class="emp_tr_t">@item.EmployeeName</td>
                <td class="emp_tr_t">@item.phone</td>
                <td class="emp_tr_t">@item.email</td>

                <td class="emp_tr_t">@item.gender</td>
            

                <td class="emp_tr_t">@item.Position1.PositionName </td>
                @{
                    var date = item.enter_date;
                    var strdate = "";
                    if (date != null)
                    {
                        strdate = DateTime.Parse(date.ToString()).ToString("yyyy年MM月dd日");
                    }
                }
                <td class="emp_tr_t">@strdate</td>

                <td class="emp_tr_t @(item.state==0?"":"re")">
                    @(item.state==0?"在职":"离职")
                </td>
                <td>
                    <button type="button" onclick="fuzhi(@item.id,@item.state,'@item.EmployeeName')" class="layui-btn layui-btn-sm">复职</button>
                </td>


            </tr>
            numid++;
        }
    </table>

</div>

<div class="demo-laypage-pn-show">
    @Html.ActionLink("上一页", "Leave_Record", new { page = ViewBag.CurrentPage - 1 }, new { @class = "layui-btn" })
    @for (int i = 1; i <= ViewBag.TotalPages; i++)
    {
        if (i == ViewBag.CurrentPage)
        {
            @Html.Label($"{@i}", new { @class = "layui-btn layui-btn-sm layui-btn-warm" }) ;
        }
        else
        {
            @Html.ActionLink(i.ToString(), "Leave_Record", new { page = i }, new { @class = "layui-btn layui-btn-primary layui-btn-sm" });
        }
    }
    @Html.ActionLink("下一页", "Leave_Record", new { page = ViewBag.CurrentPage + 1 }, new { @class = "layui-btn" })
</div>
<script>
    function fuzhi(id, state,name) {
        if (confirm("确认让"+name+'复职吗？')) {      
        $.ajax({
            url: '/home/resume',
            type: 'POST',
            data: { id, state },
            success: function (result) {
                alert('修改入职成功！再次欢迎' + name +"的加入！");
                location.reload();
                // 获取当前的分页参数
                var currentPage = getCurrentPage(); // 自定义函数，用于获取当前页码
                var pageSize = getPageSize(); // 自定义函数，用于获取每页显示的数量
                // 构建重定向的 URL
                var redirectUrl = '/home?page=' + currentPage + '&pageSize=' + pageSize;
                // 添加一个特殊的查询参数
                redirectUrl += '&refresh=true';
                // 重定向到当前页面的 URL
                window.location.href = redirectUrl;
            },
            error: function (xhr, status, error) {
                // 处理错误
                alert('修改失败');
            }
        });

        // 在页面加载时检查查询参数并执行刷新
        $(document).ready(function () {
            var urlParams = new URLSearchParams(window.location.search);
            var refresh = urlParams.get('refresh');

            if (refresh === 'true') {
                // 执行页面刷新
                location.reload();
            }
        });
        }
    }
</script>
